<template>
	<view class="">
		<view class="m-2">规格名称</view>
		<view class="m-2 p-3 rounded-20 bg-white">
			<input value="" placeholder="输入规格名称, 例如: 尺码" v-model="attr_name" @input="change_name" maxlength="20" />
			<view class="text-999 text-right mt-3">{{count}}/20</view>
		</view>
		<view class="m-2">规格属性</view>
		<view class="m-2 p-3 rounded-20 bg-white h-50">
			<view class="text-999"></view>
			<view class="mt-1">
				<textarea value="" placeholder='输入可选规格属性，例如大码中码小码，每输入一个属性值，使用换行符，输入第二个属性值' v-model="large" @input="large_input"  />
			</view>
		</view>
		<view class="text-999 m-2">
			每行一个可选参数值, 多个请换行输入
		</view>
		<u-toast ref="uToast" />
		
		<view class="footer"></view>
		<view class="bg-white release py-2 w-100 position-fixed bottom-0">
			<button type="warn" @click="preserve">保存</button>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				attr_name:"", // 规格名称
				specification_id:0, // 规格ID
				goods_id:0, // 商品ID
				
				count:0, // 计数
				large:"", // 大码
				desc:``
			}
		},
		methods:{
			// 规格名称
			change_name(e){
				console.log(e)
				this.attr_name=e.detail.value
				this.count=e.detail.cursor
			},
			// 大码
			large_input(e){
				this.large=e.detail.value
			},
			// 中码
			medium_input(e){
				this.medium=e.detail.value
			},
			// 小码
			small_input(e){
				this.small=e.detail.value
			},
			// 保存
			preserve(){
				if(this.attr_name==""){
					this.$u.toast("请输入规格名称")
				}else if(this.large==""){
					this.$u.toast("请输入规格属性")
				}else{
					this.$H.post("v2/store/goods/specification/attribute/add",{
						specification_id:this.specification_id,
						goods_id:this.goods_id,
						attr_name:this.attr_name,
						attr_values:this.large.split("\n")
					}).then(res=>{
						if(res.status.succeed==0){
							this.$refs.uToast.show({
								title: res.status.error_desc,
								type: 'default',
							})
						}else{
							this.$refs.uToast.show({
								title: '添加成功',
								type: 'success',
								back: true
							})
							getApp().globalData.spec_add="添加"
						}
					})
				}
			},
			
		},
		onLoad(e) {
			this.goods_id=e.goods_id
			this.specification_id=e.specification_id
		}
	}
</script>

<style>
	textarea{
		height: 200upx;
	}
</style>
